
package com.rt.schedulenew.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.rt.schedulebase.dto.DictDeptDto;
import com.rt.schedulebase.entity.DictDept;
import com.rt.schedulebase.mapper.DictDeptMapper;
import com.rt.schedulenew.api.IDictDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rt.schedulenew.utils.base.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictDeptServiceImpl extends ServiceImpl<DictDeptMapper, DictDept> implements IDictDeptService
{

    @Override
    public List<DictDept> getList(DictDeptDto dto) {
        QueryWrapper<DictDept> qw = new QueryWrapper<>();
        Map<String, Object> map = new HashMap<>();
        map.put("HOSPITAL_CODE", dto.getHospitalCode());
        if (StringUtils.isNotBlank(dto.getDeptCode())) {
            qw.in("DEPT_CODE", CommonUtil.split2List(dto.getDeptCode()));
        }
        if (StringUtils.isNotBlank(dto.getClinicAttr())) {
            qw.in("CLINIC_ATTR", CommonUtil.split2List(dto.getClinicAttr()));
        }
        if (StringUtils.isNotBlank(dto.getDeptName())) {
            qw.like("DEPT_NAME", dto.getDeptName());
        }
        qw.allEq(map,false);
        qw.orderByAsc("SORT_NO");
        List<DictDept> list = baseMapper.selectList(qw);
        return list;
    }

    @Override
    public List<DictDept> getListAll() {
        return baseMapper.selectList(null);
    }


    @Override
    public DictDept getInfo(DictDeptDto dto) {
        QueryWrapper<DictDept> qw = new QueryWrapper<>();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("HOSPITAL_CODE", dto.getHospitalCode());
        map.put("DEPT_CODE", dto.getDeptCode());
        map.put("DEPT_NAME", dto.getDeptName());
        map.put("CLINIC_ATTR", dto.getClinicAttr());
        qw.allEq(map, false);
        return baseMapper.selectOne(qw);
    }

    @Override
    public List<DictDept> getPerformDept(DictDeptDto dto) {
        if (StringUtils.isNotBlank(dto.getClinicAttr())) {
            dto.setClinicAttrList(CommonUtil.split2List(dto.getClinicAttr()));
        }
        if (StringUtils.isNotBlank(dto.getExamClass())) {
            dto.setExamClassList(CommonUtil.split2List(dto.getExamClass()));
        }
        List<DictDept> list = baseMapper.getPerformDept(dto);
        return list;
    }

    @Override
    public List<DictDept> getNurseUnit() {
        QueryWrapper<DictDept> qw = new QueryWrapper<>();
        qw.like("DEPT_NAME", "单元");
        return baseMapper.selectList(qw);
    }
}
